* ============================================================================ *
* PROJECT:		The Effects of Proposal Power on Incumbents’ Vote Share:
*				Updated Results from a Naturally-Occurring Experiment
* JOURNAL: 		Political Science Research Methods
* OBJECTIVE		Replicating Loewen et al. using their data
* AUTHOR: 		Semra Sevi and Donald P. Green  
* DATE:			2021-01-10
* ============================================================================ *

*Load dataset
use "loewen_data.dta"


*Loewen et al's code to set up their data

*****Data set-up
**excluding two excluded members
drop if excluded==1
**indicator of legislation initiated in the Senate
replace senate=0 if senate==.
**indicator for members who had to power to propose but did not
gen OPTOUT=0
replace OPTOUT=1 if place<=87 & election==2006 & check==0
replace OPTOUT=1 if place<117 & election==2008 & check==0

***creating indicator of power to propose
gen P2P=0
replace P2P=1 if place<=87 & election==2006 
replace P2P=1 if place<117 & election==2008
**interaction with membership in government caucus
gen govP2P=gov*P2P




*Our code using Loewen et al's data

*Figure 1: Incumbent Vote Shares by Session, Membership in the Governing Party, and Data Source

*Fix label for election to match our data
label define election_lab 2006 "2004-2006" 2008 "2006-2008"
label values election election_lab
*Create the means for graph
summarize current if election == 2006 & gov == 0 & P2P == 0
local mean_2006_gov0_p2p0 = round(r(mean),.01)
local n_2006_gov0_p2p0 = r(N)
summarize current if election == 2006 & gov == 0 & P2P == 1
local mean_2006_gov0_p2p1 = round(r(mean),.01)
local n_2006_gov0_p2p1 = r(N)
summarize current if election == 2006 & gov == 1 & P2P == 0
local mean_2006_gov1_p2p0 = round(r(mean),.01)
local n_2006_gov1_p2p0 = r(N)
summarize current if election == 2006 & gov == 1 & P2P == 1
local mean_2006_gov1_p2p1 = round(r(mean),.01)
local n_2006_gov1_p2p1 = r(N)
summarize current if election == 2008 & gov == 0 & P2P == 0
local mean_2008_gov0_p2p0 = round(r(mean),.01)
local n_2008_gov0_p2p0 = r(N)
summarize current if election == 2008 & gov == 0 & P2P == 1
local mean_2008_gov0_p2p1 = round(r(mean),.01)
local n_2008_gov0_p2p1 = r(N)
summarize current if election == 2008 & gov == 1 & P2P == 0
local mean_2008_gov1_p2p0 = round(r(mean),.01)
local n_2008_gov1_p2p0 = r(N)
summarize current if election == 2008 & gov == 1 & P2P == 1
local mean_2008_gov1_p2p1 = round(r(mean),.01)
local n_2008_gov1_p2p1 = r(N)

*N for the graph
summarize current if election == 2006 
local n_2006 = r(N)
summarize current if election == 2008 
local n_2008 = r(N)	

*Create figure 
graph box current if election == 2006, over(P2P, relabel(1 "Control" 2 "Treatment")label(labsize(*1))) ///
	over(gov, relabel(1 "Opposition" 2 "Government")) ///
	ytitle("") intensity(0) ///
	medline(lcolor(grey*.5)) marker(1,mfcolor(white)) ///
	text(42 9 "{&mu}=`mean_2006_gov0_p2p0'" 36 9 "N=`n_2006_gov0_p2p0'" ///
	37 33 "{&mu}=`mean_2006_gov0_p2p1'" 31 33 "N=`n_2006_gov0_p2p1'" ///
	35 69 "{&mu}=`mean_2006_gov1_p2p0'" 29 69 "N=`n_2006_gov1_p2p0'" ///
	34 90 "{&mu}=`mean_2006_gov1_p2p1'" 28 90 "N=`n_2006_gov1_p2p1'", place(e)size(small)) ///	
	yscale(range(-5 85)) ylabel(0(20)80) title("2004-2006 (N=`n_2006')", box width(126)) saving("loewen_data_f1")
	
graph box current if election == 2008, over(P2P, relabel(1 "Control" 2 "Treatment")label(labsize(*1))) ///
	over(gov, relabel(1 "Opposition" 2 "Government")) ///
	ytitle("") intensity(0) ///
	medline(lcolor(grey*.5)) marker(1,mfcolor(white)) ///
	text(36 9 "{&mu}=`mean_2008_gov0_p2p0'" 30 9 "N=`n_2008_gov0_p2p0'" ///
	38 33 "{&mu}=`mean_2008_gov0_p2p1'" 32 33 "N=`n_2008_gov0_p2p1'" ///
	45 69 "{&mu}=`mean_2008_gov1_p2p0'" 39 69 "N=`n_2008_gov1_p2p0'" ///
	37 90 "{&mu}=`mean_2008_gov1_p2p1'" 31 90 "N=`n_2008_gov1_p2p1'", place(e)size(small)) ///		
	yscale(range(-5 85)) ylabel(0(20)80) title("2006-2008 (N=`n_2008')", box width(126)) saving("loewen_data_f2")	

graph combine loewen_data_f1.gph loewen_data_f2.gph, col(1) title("Loewen et al.'s data") ycommon saving("loewen")


**A2.2: Replication of Loewen et al. 2014 using their data 
eststo clear
eststo: regress current gov P2P previous ib1.election if election == 2006 | election == 2008, robust 
eststo: regress current gov P2P previous ib1.election if election == 2006 | election == 2008, cluster(id)
eststo: regress current i.gov##i.P2P previous ib1.election if election == 2006 | election == 2008, robust	
eststo: regress current i.gov##i.P2P previous ib1.election if election == 2006 | election == 2008, cluster(id)	
ereturn list	
* Saves table in rtf file 
esttab using "A2.2_columns1and3.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		scalars("N N" "r2 R2" "r2_a R2 Adj." "rmse Root MSE") 
